﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using VM.BLL.DataBase;
using VM.Common.EntityEnum;
using VM.Common.Result;
using VM.Entity.EntityDto.ICon;
using VM.Entity.EntityMap.ICon;
using VM.Entity.EntityMap.System.Code;
using VM.IBLL.ICon;
using VM.IDAL.System.Code;
using VM.WebCore.Jwt;
using VM.WebCore.SwaggerExtend;
using VM.Wechat;

namespace VM.WebAPI.Controllers
{
    [Route("api/icon")]
    [ApiController]
    public class IconController : ControllerBase
    {


        private readonly IIconBLL _IIConBLL;
        private readonly IJWTService _IJWTService;
        private readonly IHttpContextAccessor _HttpContextAccessor;


        public IconController(IJWTService iJWTService, IIconBLL iIConBLL, IHttpContextAccessor httpContextAccessor)
        {

            _IIConBLL = iIConBLL;
            _IJWTService = iJWTService;
            _HttpContextAccessor = httpContextAccessor;
        }
        /// <summary>
        /// 添加编码规则
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]//要求通过授权才行---只要能鉴权成功，都能通过] PC
        [Route("addIcon")]
        [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ApiVersions.V1))]
        public ApiResult addIcon(addIconDto obj)
        {
            //解析Jwt,获取到UserId
            int UserId = _IJWTService.GetUserIdByAuthInfoStr();
            //解析并优化类的传参
            obj = _IIConBLL.perfectClass<addIconDto>(obj, UserId, ProTypeEnum.save);
            return _IIConBLL.addIcon(obj);
        }


        /// <summary>
        /// 获取图标列表   PC
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize]//要求通过授权才行---只要能鉴权成功，都能通过]
        [Route("getIconList")]
        [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ApiVersions.V1))]
        public ApiDataResult<PagingData<getIconListDto>> getDataBaseTypeList(string? name = "", int pageIndex = 1, int pageSize = 16)
        {
            //解析Jwt,获取到UserId
            int UserId = _IJWTService.GetUserIdByAuthInfoStr();
            //校验验证码是否可用，如果可用，返回true
            ApiDataResult<PagingData<getIconListDto>> Res = _IIConBLL.getIconList(name, UserId, pageSize, pageIndex);
            return Res;
        }

    }
}
